package uk.co.leandro.views
{
	import org.robotlegs.mvcs.Mediator;
	
	import uk.co.leandro.events.GameEvent;
	import uk.co.leandro.events.TimeEvent;
	
	public class GameViewMediator extends Mediator
	{
		[Inject]
		public var view:GameView;
		
		override public function onRegister():void
		{
			super.onRegister();
			trace("Game mediator on register");
			addContextListener(TimeEvent.TICK, tickHandler);
			addViewListener(GameEvent.START, startHandler);
			addViewListener(GameEvent.STOP, stopHandler);
		}
		
		private function startHandler(e:GameEvent):void
		{
			trace("view mediator");
			dispatch(new GameEvent(GameEvent.START));
		}
		
		private function stopHandler(e:GameEvent):void
		{
			dispatch(new GameEvent(GameEvent.STOP));
		}
		
		private function tickHandler(e:TimeEvent):void
		{
			view.updateTime(e.countDown);
		}
	}
}